package com.autodatabase.database;

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;

public class Test {
	public static void main(String[] args) {
		try {
			String driverClassName = "com.mysql.jdbc.Driver";
			String url = "jdbc:mysql://localhost:3306";
			String userName = "root";
			String password = "root123";
			Class.forName(driverClassName);
			
			try {
				Connection conn = DriverManager.getConnection(url, userName, password);
				ResultSet rs = null;

				DatabaseMetaData dmd = conn.getMetaData();
				// 数据库名:
				System.out.println("数据库名 :" + dmd.getDatabaseProductName());
				// 数据库版本号:
				System.out.println("数据库版本号:"
						+ dmd.getDatabaseProductVersion());
				// 驱动程序
				System.out.println("驱动程序:" + dmd.getDriverName());

				// 驱动版本
				System.out.println("驱动版本 :" + dmd.getDriverVersion());

				// 数据库的数据类型列表
				rs = dmd.getTypeInfo();
				System.out.println("数据类型列表");
				while (rs.next()) {
					System.out.println(rs.getString(1));
				}
				
				rs = dmd.getCatalogs();
				
				while (rs.next()) {
					System.out.println(rs.getString(1) + "," + rs.getString("TABLE_CAT"));
				}
				
				rs = dmd.getTables("jeecmsv5", null, null, null);
				
				while (rs.next()) {
					System.out.println(rs.getString("TABLE_NAME"));
				}
				
			} 
			catch (SQLException e) {
				e.printStackTrace();
			}
		} 
		catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
	}
}
